home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-01 / zendisk1.zip / LST7-14.ASM < prev    next >
Assembly Source File  |  1990-02-15  |  994b  |  43 lines

  1. ;
  2. ; *** Listing 7-14 ***
  3. ;
  4. ; Performs bit-doubling of a byte in AL to a word in AX
  5. ; by using doubled shifts, one from each of two source
  6. ; registers. This approach avoids branching and is very
  7. ; fast according to official instruction timings, but is
  8. ; actually quite slow due to instruction prefetching.
  9. ;
  10. ; (Based on an approach used in "Optimizing for Speed,"
  11. ; by Michael Hoyt, Programmer's Journal 4.2, March, 1986.)
  12. ;
  13. ; Macro to double each bit in a byte.
  14. ;
  15. ; Input:
  16. ;    AL = byte to bit-double
  17. ;
  18. ; Output:
  19. ;    AX = bit-doubled word
  20. ;
  21. ; Registers altered: AX, BX
  22. ;
  23. DOUBLE_BYTE    macro
  24.     mov    ah,al    ;put the byte to double in two
  25.             ; registers
  26.     mov    bx,ax
  27.     rept    8
  28.     shr    bl,1    ;get the next bit to double
  29.     rcr    ax,1    ;move it into the msb...
  30.     shr    bh,1    ;...then get the bit again...
  31.     rcr    ax,1    ;...and replicate it
  32.     endm
  33.     endm
  34. ;
  35.     call    ZTimerOn
  36. BYTE_TO_DOUBLE=0
  37.     rept    100
  38.     mov    al,BYTE_TO_DOUBLE
  39.     DOUBLE_BYTE
  40. BYTE_TO_DOUBLE=BYTE_TO_DOUBLE+1
  41.     endm
  42.     call    ZTimerOff
  43.